package com.hepinghospital.user.ui.activity.userinfo;

import android.content.Context;
import android.graphics.Typeface;
import android.view.View;
import android.widget.TextView;

import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentManager;
import androidx.fragment.app.FragmentPagerAdapter;
import androidx.viewpager.widget.ViewPager;

import com.google.android.material.tabs.TabLayout;
import com.hepinghospital.user.R;
import com.hepinghospital.user.base.BaseActivity;
import com.hepinghospital.user.ui.fragment.MyCloudOrderFragment;
import com.hepinghospital.user.ui.fragment.MyDiagnoseOrderFragment;

import java.util.Objects;

import butterknife.BindView;

/**
 * 我的问诊界面
 *
 * @time 2021/4/10 20:05
 */

public class MyAskActivity extends BaseActivity {
    @BindView(R.id.timeline_tablayout)
    TabLayout mTabLayout;
    @BindView(R.id.timeline_viewpager)
    ViewPager mViewPager;

    int page, type;

    @Override
    protected void initViews() {
        mViewPager.setAdapter(new HistoryFragmentAdapter(this, getSupportFragmentManager()));
        mTabLayout.setupWithViewPager(mViewPager);
        mViewPager.setCurrentItem(type);
        Objects.requireNonNull(mTabLayout.getTabAt(type)).select();
    }

    @Override
    protected void initData() {
        page = getIntent().getIntExtra("page", 0);
        type = getIntent().getIntExtra("type", 0);
    }

    class HistoryFragmentAdapter extends FragmentPagerAdapter {

        private static final int PAGE_COUNT = 2;

        private Context mContext;

        HistoryFragmentAdapter(Context context, FragmentManager fm) {
            super(fm);
            this.mContext = context;
        }

        @Override
        public Fragment getItem(int position) {
            if (position == 0) {
                return MyCloudOrderFragment.newInstance(1, page);
            }
            return MyDiagnoseOrderFragment.newInstance(2, page);
        }

        @Override
        public int getCount() {
            return PAGE_COUNT;
        }

        @Override
        public CharSequence getPageTitle(int position) {
            if (position == 0) {
                return "云门诊";
            }
            return "图文咨询";
        }

    }

    @Override
    protected int getLayoutResource() {
        return R.layout.activity_my_ask;
    }
}
